﻿#region 信息
// Copyright©2014 Rex Rao all rights reserved.
// File name : Mojito\Sohobloo.SoMcCoffee\MefProgramConfig.cs
// Author : Sohobloo
// Create time : 2014/08/27 17:40
// Update time : 2014/08/27 17:40
#endregion

using System;
using System.ComponentModel.Composition.Hosting;
using System.IO;
using System.Reflection;

namespace Sohobloo.SoMcCoffee.Mef
{
    public static class MefProgramConfig
    {
        private static CompositionContainer _container;

        public static void RegisterSolver<T>()
        {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog(Directory.GetCurrentDirectory()));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetAssembly(typeof(T))));
            _container = new CompositionContainer(catalog);
        }

        public static T GetExportedProgram<T>()
        {
            return _container.GetExportedValue<T>();
        }
    }
}